package com.api.shopapi.mapper;

import com.api.shopapi.entity.GoodsColor;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
@Mapper
public interface GoodsColorMapper {

    @Insert("insert into goods_color values " +
            "(#{goodsColor.GoodsColorCode},#{goodsColor.Name},#{goodsColor.Status})")
    int insert(@Param("goodsColor") GoodsColor goodsColor);


    @Update("update goods_color set Status=2 where GoodsColorCode=#{goodsColorCode}")
    int delete(@Param("goodsColorCode")String goodsColorCode);

    @Update("update goods_color set Name=#{goodsColor.Name},Status=#{goodsColor.Status} " +
            "where GoodsColorCode=#{goodsColor.GoodsColorCode}")
    int update(@Param("goodsColor") GoodsColor goodsColor);

    @Select("select * from goods_color where GoodsColorCode=#{goodsColorCode} limit 1")
    GoodsColor getByGoodsColorCode(@Param("goodsColorCode") String goodsColorCode);

    @Select("select * from goods_color where status=1")
    List<GoodsColor> getList();

    @Select("<script>" +
            "select * from goods_color where 1=1 " +
            "<if test ='name !=null and name!=\"\" '>" +
            " and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status!=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            "</script>")
    List<GoodsColor> getPageList(@Param("name") String name,@Param("status") int status);

}
